package com.wcy.bysj.controller;


import com.wcy.bysj.common.MyException;
import com.wcy.bysj.common.Result;
import com.wcy.bysj.common.ResultEnum;
import com.wcy.bysj.entity.Class;
import com.wcy.bysj.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/class")
public class ClassController {

    @Autowired
    private ClassService classService;

    @RequestMapping("/selectAllClass")
    @ResponseBody
    public Result selectAllClass(@RequestBody Class c) {
        try{
            return classService.selectAllClass(c);
        } catch (MyException me) {
            me.printStackTrace();
            return Result.error(ResultEnum.ERROR.getCode(),"查询失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(ResultEnum.ERROR.getCode(),"查询失败");
        }
    }

    @RequestMapping("/addClass")
    @ResponseBody
    public Result addClass(@RequestBody Class c) {
        try{
            return classService.addClass(c);
        } catch (MyException me) {
            me.printStackTrace();
            return Result.error(ResultEnum.ERROR.getCode(),"查询失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(ResultEnum.ERROR.getCode(),"查询失败");
        }
    }

    @RequestMapping("/updateClass")
    @ResponseBody
    public Result updateClass(@RequestBody Class c) {
        try{
            return classService.updateClass(c);
        } catch (MyException me) {
            me.printStackTrace();
            return Result.error(ResultEnum.ERROR.getCode(),"查询失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(ResultEnum.ERROR.getCode(),"查询失败");
        }
    }

    @RequestMapping("/deleteClass")
    @ResponseBody
    public Result deleteClass(@RequestBody Class c) {
        try{
            return classService.deleteClass(c);
        } catch (MyException me) {
            me.printStackTrace();
            return Result.error(ResultEnum.ERROR.getCode(),"查询失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(ResultEnum.ERROR.getCode(),"查询失败");
        }
    }

}
